package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.neuedu.ssmp.crm.entity.Chances;
import org.neuedu.ssmp.crm.entity.SysUser;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.IChancesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/marketing")
@Slf4j
public class ChancesController {
    @Autowired
    private IChancesService chancesService;

    @GetMapping("chances")
    public List<Chances> list(){
//        return chancesService.list();
        return chancesService.page();
    }
    @PostMapping("edit")
    public ResponseEntity edit(@RequestBody Chances chances){
        chancesService.updateById(chances);
        return ResponseEntity.ok("成功");
    }
    @PostMapping("add")
    public ResponseEntity add(@RequestBody Chances chances){
        chancesService.save(chances);
        return ResponseEntity.ok("成功");
    }
    @PostMapping("query")
    public List<Chances> select(@RequestParam(value = "name" , defaultValue = "" ,name = "name")String name){
        QueryWrapper<Chances> wrapper = new QueryWrapper<>();
        wrapper.like("name",name);
        return chancesService.list(wrapper);
    }

    //开发计划表格查询
    @GetMapping("list")
    public List<Chances> chancesList(@RequestParam String name){
        QueryWrapper<Chances> wrapper = new QueryWrapper<>();
        wrapper.eq("state",2).eq("username",name);
        return chancesService.list(wrapper);
    }
    @PostMapping("find")
    public Chances find(@RequestParam Integer id){
        return chancesService.getById(id);
    }
    @GetMapping("lists")
    public Chances chancesLists(@RequestParam Integer id){
        return chancesService.lists(id);
    }
    @PostMapping("delet")
    public ResponseEntity del(@RequestParam Integer id){
        chancesService.removeById(id);
        return ResponseEntity.ok("成功");
    }

}
